home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 620 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.3 KB

  1. Path: chronicle.mti.sgi.com!austern
  2. From: steven2@salesbook.com (Steve Nutt)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Semantics of "new foo[0]"
  5. Date: 04 Mar 1996 10:25:47 PST
  6. Organization: DET
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4hb8hu$afq@post.acadia.net>
  9. References: <MGB.96Feb27175316@kronecker.mitre.org>
  10. Reply-To: steven2@salesbook.com
  11. NNTP-Posting-Host: isolde.mti.sgi.com
  12. X-Original-Date: Sun, 03 Mar 1996 07:20:42 GMT
  13. X-Newsreader: Forte Free Agent 1.0.82
  14. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  15.     iQBVAwUBMTs1v0y4NqrwXLNJAQE22gIApVMIFnpE1oZfSQeEqCPh+YJJfj9BUK3x
  16.     Fpr1IL2xsSCZcOGhcrnT7CcMvSpG7batkc9Jis0ummQaIeHyY5SyHw==
  17.     =BsjR
  18. Originator: austern@isolde.mti.sgi.com
  19.  
  20. mgb@kronecker.mitre.org (G. Mike Butler D054) wrote:
  21.  
  22. >According to the ARM section 5.3.3:
  23. >     "operator new() can be called with the argument
  24. >      zero.  Repeated such calls return pointers to
  25. >      distinct objects."  
  26. >      
  27. >But when I execute the following:
  28. >    #include <isotream.h>
  29. >    main()
  30. >    {
  31. >      struct foo { char a[1024]; };
  32. >      foo *p = new foo[0];
  33. >      foo *q = new foo[0];
  34.  
  35. >      cout << (void *)p << " " << (void *)q << endl;
  36. >    }
  37.  
  38. >I get
  39. >    0x338d8 0x338e8
  40.  
  41. >While these are distinct pointers, the pointers refer to overlapping
  42. >objects. Is this a legitimate interpretation of section 5.3.3 or is
  43. >this a compiler/library bug?
  44.  
  45. >Incidentally, the standard template library included with gcc 2.7.2
  46. >relies on "operator new(0)" working.
  47.  
  48. >Thanks,
  49. >-Mike Butler
  50. >---
  51. >[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  52. >                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  53. >  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  54. >  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  55. >  Comments? mailto:std-c++-request@ncar.ucar.edu 
  56. >]
  57.  
  58. Why do you say these are overlapping objects? You have not allocated
  59. any objects of type foo. I would say the operator new foo[0] is
  60. working as expected for you.
  61.  
  62. Steve
  63. ---
  64. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  65.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  66.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  67.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  68.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  69. ]
  70.